#!/bin/sh
#
#


BB_CONFIG=scripts/defconfig


# sed -i 's/^\(EXTRAVERSION.*=\).*/\1 -noon/' Makefile
sed -i 's/^\(ARCH.*=\).*/\1 arm/' Makefile
sed -i "s/^\(CROSS_COMPILE.*=\).*/\1 ${TARGET_PLAT}-/" Makefile

cp -v ${PREGEN_PATH}/config.busybox ${BB_CONFIG} || exit 1

if [ "${USE_UDEV}" = "1" ]; then
	sed -i 's/^\(CONFIG.*_MDEV_.*\)=y/# \1 is not set/g' ${BB_CONFIG}
fi

make defconfig > /dev/null 2>&1

# sed -i 's/\(message.*\)init started.*/\1\\n\\t********************************\\n\\t*   Welcome to MaxWit Linux!   *\\n\\t********************************\\n");/' init/init.c
sed -i 's/init started\:\ //' init/init.c
sed -i '/new_init_action.*VC_/d' init/init.c
sed -i 's/^\(static.*log_console =\).*/\1 NULL;/' init/init.c
sed -i '/Log the process/,+3d' init/init.c
sed -i '/NB.*wait for/,+24d' init/init.c

sed -i "s:\(^#define BANNER.*BB_VER\).*:\1 \" for MaxWit Linux (${MWL_VER})\":" libbb/messages.c
sed -i 's/\(.*\) ALIGN1 =/ALIGN1 \1 =/' libbb/messages.c

sed -i 's/\(text.*=.*PS1=.*\)w /\1w/' shell/ash.c
sed -i 's/\(text.*=.*PS1=\)/\1maxwit:/' shell/ash.c

for file in init/init.c shell/ash.c; do
	sed -i 's/\(.*\) MAIN_EXTERNALLY_VISIBLE;/MAIN_EXTERNALLY_VISIBLE \1;/' ${file}
	sed -i 's/\(^[a-zA-Z].*\) ALIGN1 =/ALIGN1 \1 =/' ${file}
	sed -i 's/\<iflag\>/IFLAG/g' ${file}
	sed -i 's/\<ifsval\>/IFSVAL/g' ${file}
	sed -i 's/\<ifsset>/IFSSET/g' ${file}
done

make V=1 -j4 && \
make CONFIG_PREFIX=${SYSROOT_PATH} install || exit 1


